//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#include <bsp.h>
#include <mmu.h>
#include <init.h>
#include <bootinfo.h>
#include <timer.h>

STATIC DECL_CODEINIT void ParseBootCommandLine()
{
}

EXTERN_C DECL_CODEINIT void CDECL WriteFlash(BootInfo *pBootInfo);
EXTERN_C void InitBSPUser();
DECL_ASMLINKAGE DECL_CODEINIT void BspStartup(BootInfo *pBootInfo)
{
    // Setup
    KrnSetup(
        KERNEL_PHYSBASE, KERNEL_IMAGEPHYSBASE,
        KERNEL_MEMMAPPEDIOBASE, KERNEL_MEMMAPPEDIOLIMIT,
        0, 0);

    pBootInfo = (BootInfo *)VIRTADDR((physaddr_t)pBootInfo);

    kprintf("\n<Boot Info> (0x%08x)\n"
            "LoadAddress:       0x%08x\n"
            "ImageBase:         0x%08x\n"
            "ImageSize:         0x%08x\n"
            "MemorySize:        0x%08x\n"
            "WriteMagic:        0x%08x\n",
            pBootInfo,
            pBootInfo->LoadAddress,
            pBootInfo->ImageBase,
            pBootInfo->ImageSize,
            pBootInfo->MemorySize,
            pBootInfo->WriteMagic);
    // Initialize
    InitConsole();

    InitBootModules();

    ParseBootCommandLine();

    InitMemoryZones();

    InitRTC();

    InitPIC();

    InitPIT();

#if !defined(_TEST_TYPE) /* Test console uses serial3 */
//    InitBSPUser();
#endif //_TEST_TYPE

    if (!KrnInitialize()) {
        BspHalt();
    }

    KrnStartup();

    assert0msg("Kernel startup failed");
    BspHalt();
}

BspGlobals bsp = {
    "ARM",                    // *szCpuDescription
    "s3c6410",                  // *szBoardDescription

    KERNEL_PHYSBASE,          // paKernelPhysBase
    KERNEL_IMAGEPHYSBASE,     // paKernelImagePhysBase

    NULL,                     // *pMemoryZones
    0,                        // uNumberOfMemoryZones

    NULL,                     // *pMemoryHoles
    0,                        // uNumberOfMemoryHoles

    0,                        // uDmaPreferredZoneNo
    0,                        // uKernelPreferredZoneNo
    0,                        // uUserPreferredZoneNo

    {0, 0},                   // regionOfInitStack

    NULL,                     // *pBootModules
    0,                        // uNumberOfBootModules
    {0, 0},                   // regionOfBootModules

    NULL,                     // *szBootCommandLine

    0,                        // uIrqBase
    64,                       // uNumberOfIrqs

    PIT_Irq,                  // irqOfPIT
    IPL0                      // iplOfPIT
};
